package com.huq.io;

import java.nio.ByteBuffer;

import sun.nio.ch.DirectBuffer;

public class DirectByteBufferCleaner {

    public static void clean(final ByteBuffer buffer) {
        if (buffer.isDirect()) {
            ((DirectBuffer) buffer).cleaner().clean();
        }
    }

    public static void sleep(long time) {
        try {
            Thread.sleep(time);
        } catch (Exception e) {
        }
    }

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 100);
        System.out.println("start");
        sleep(10000);
        clean(buffer);
        System.out.println("end");
        sleep(10000);
    }

}
